/* Generic Create command for salesforce */
package poler.control.command
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	import com.salesforce.AsyncResponder;
	
	import mx.rpc.IResponder;
	import mx.utils.ObjectUtil;
	
	import poler.classes.AbstractCommand;
	import poler.control.events.CreateEvent;
	import poler.model.ModelLocator;

	
	
	public class CreateCmd extends AbstractCommand implements ICommand, IResponder
	{
		private var _amLocator:ModelLocator = ModelLocator.getInstance();
		private var cFunction:Function;
	
		public function execute(event:CairngormEvent):void
		{
			
			
			if((event as CreateEvent).Callback != null){
				cFunction = (event as CreateEvent).Callback;
			}
			
			var context:Array = (event as CreateEvent).Context;				
			_amLocator.Apex.create(context,new AsyncResponder(result));
		}
		
		public function result(data:Object):void
		{	
			if(cFunction != null){
				cFunction(data);
			}
			trace('Create result: '+ObjectUtil.toString(data));
			
		}
		
	//	
	}
}